package cn.bdqn.asecu.service;

import cn.bdqn.pojo.Operationlog;
import cn.bdqn.pojo.Project;
import cn.bdqn.pojo.Worklog;
import cn.bdqn.repository.Asecu_OperationLogRepository;
import cn.bdqn.repository.Asecu_ProjectRepository;
import cn.bdqn.repository.Asecu_WorkLogRepository;
import cn.bdqn.vo.UserWorkLog;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 日志业务类
 * @author 8
 */
@Service
public class AsecuLogService {

    @Resource
    Asecu_OperationLogRepository asecu_operationLogRepository;

    @Resource
    Asecu_WorkLogRepository asecu_workLogRepository;

    @Resource
    Asecu_ProjectRepository asecu_projectRepository;
    /**
     * 获取操作日志
     * @return
     */
    public List<Operationlog> getSystemLog() {
        List<Operationlog> list = asecu_operationLogRepository.findAll();
        return  list;
    }

    /**
     * 获取项目名称
     * @return
     */
    public List<Project> getProject(){
        List<Project> list = asecu_projectRepository.findAll();
        return list;
    }

    /**
     * 添加工作日志
     * @param worklog
     * @return
     */
    @Transactional
    public boolean addWorkLog(Worklog worklog) {
        Worklog save = asecu_workLogRepository.save(worklog);
        if (save!=null){
            return true;
        }
        return false;
    }

    /**
     *
     * @return
     */
    public List<UserWorkLog> getWorkLog(Integer id, String project, Date workdate) {
        List<UserWorkLog> work = asecu_workLogRepository.findWork(id,project,workdate);
        for (UserWorkLog userWorkLog : work) {
            System.out.println(userWorkLog);
        }
        return work;
    }

    /**
     * 删除
     * @param ids
     */
    @Transactional
    public void delWorkLog(Integer[] ids) {
        for (Integer id : ids) {
            asecu_workLogRepository.deleteById(id);
        }
    }

    /**
     * 查看
     * @param id
     * @return
     */
    public Worklog worklog_view(Integer id) {
        Worklog worklog = asecu_workLogRepository.findById(id).get();
        return worklog;
    }

    /**
     * 修改工作日志
     * @param worklog
     * @return
     */
    @Transactional
    public Worklog saveWorkLog(Worklog worklog) {
        Worklog save = asecu_workLogRepository.save(worklog);
        return save;
    }
}
